<!DOCTYPE html>
<html>
<head><meta name="generator" content="Hexo 3.9.0">
  <meta charset="utf-8">
  
  <title>【spark】pyspark之dataframe | MaxMa</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  
  <meta name="keywords" content="sparkDataFrame">
  
  
  
  
  <meta name="description" content="1 思维导图首先先上一个整理的思维导图，这个与之前整理的RDD相类似，所以可视化的部分这里我就略去了。 DataFrame的API以及操作要比RDD复杂的多，可能功能更加强大吧，但是，很幸福的事情在于： 可以用SQL完成看起来超级复杂的操作，就问你幸不幸福，开不开心！！爽爆了……  2 数据的读入（比较RDD与DataFrame）12import findsparkfindspark.init()">
<meta name="keywords" content="spark,DataFrame">
<meta property="og:type" content="article">
<meta property="og:title" content="【Spark】PySpark之DataFrame">
<meta property="og:url" content="https://anxiang1836.github.io/2019/08/11/Spark_DataFrame/index.html">
<meta property="og:site_name" content="MaxMa">
<meta property="og:description" content="1 思维导图首先先上一个整理的思维导图，这个与之前整理的RDD相类似，所以可视化的部分这里我就略去了。 DataFrame的API以及操作要比RDD复杂的多，可能功能更加强大吧，但是，很幸福的事情在于： 可以用SQL完成看起来超级复杂的操作，就问你幸不幸福，开不开心！！爽爆了……  2 数据的读入（比较RDD与DataFrame）12import findsparkfindspark.init()">
<meta property="og:locale" content="zh-CN">
<meta property="og:image" content="https://raw.githubusercontent.com/anxiang1836/FigureBed/master/img/20190821222604.png">
<meta property="og:updated_time" content="2019-11-05T17:31:47.086Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="【Spark】PySpark之DataFrame">
<meta name="twitter:description" content="1 思维导图首先先上一个整理的思维导图，这个与之前整理的RDD相类似，所以可视化的部分这里我就略去了。 DataFrame的API以及操作要比RDD复杂的多，可能功能更加强大吧，但是，很幸福的事情在于： 可以用SQL完成看起来超级复杂的操作，就问你幸不幸福，开不开心！！爽爆了……  2 数据的读入（比较RDD与DataFrame）12import findsparkfindspark.init()">
<meta name="twitter:image" content="https://raw.githubusercontent.com/anxiang1836/FigureBed/master/img/20190821222604.png">
  
    <link rel="alternate" href="/atom.xml" title="MaxMa" type="application/atom+xml">
  

  

  <link rel="icon" href="/css/images/mylogo.jpg">
  <link rel="apple-touch-icon" href="/css/images/mylogo.jpg">
  
    <link href="//fonts.googleapis.com/css?family=Source+Code+Pro" rel="stylesheet" type="text/css">
  
  <link href="https://fonts.googleapis.com/css?family=Open+Sans|Montserrat:700" rel="stylesheet" type="text/css">
  <link href="https://fonts.googleapis.com/css?family=Roboto:400,300,300italic,400italic" rel="stylesheet" type="text/css">
  <link href="//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet">
  <style type="text/css">
    @font-face{font-family:futura-pt; src:url("css/fonts/FuturaPTBold.otf") format("woff");font-weight:500;font-style:normal;}
    @font-face{font-family:futura-pt-light; src:url("css/fonts/FuturaPTBook.otf") format("woff");font-weight:lighter;font-style:normal;}
    @font-face{font-family:futura-pt-italic; src:url("css/fonts/FuturaPTBookOblique.otf") format("woff");font-weight:400;font-style:italic;}
}

  </style>
  <link rel="stylesheet" href="/css/style.css">

  <script src="/js/jquery-3.1.1.min.js"></script>
  <script src="/js/bootstrap.js"></script>

  <!-- Bootstrap core CSS -->
  <link rel="stylesheet" href="/css/bootstrap.css">

  
    <link rel="stylesheet" href="/css/dialog.css">
  

  

  
    <link rel="stylesheet" href="/css/header-post.css">
  

  
  
  

</head>
</html>


  <body data-spy="scroll" data-target="#toc" data-offset="50">


  
  <div id="container">
    <div id="wrap">
      
        <header>

    <div id="allheader" class="navbar navbar-default navbar-static-top" role="navigation">
        <div class="navbar-inner">
          
          <div class="container"> 
            <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
              <span class="sr-only">Toggle navigation</span>
              <span class="icon-bar"></span>
              <span class="icon-bar"></span>
              <span class="icon-bar"></span>
            </button>

            
              <a class="brand" style="
                 margin-top: 0px;"  
                href="#" data-toggle="modal" data-target="#myModal" >
                  <img width="124px" height="124px" alt="Hike News" src="/css/images/mylogo.jpg">
              </a>
            
            
            <div class="navbar-collapse collapse">
              <ul class="hnav navbar-nav">
                
                  <li> <a class="main-nav-link" href="/">首页</a> </li>
                
                  <li> <a class="main-nav-link" href="/archives">归档</a> </li>
                
                  <li> <a class="main-nav-link" href="/categories">分类</a> </li>
                
                  <li> <a class="main-nav-link" href="/tags">标签</a> </li>
                
                  <li> <a class="main-nav-link" href="/about">关于</a> </li>
                
                  <li><div id="search-form-wrap">

    <form class="search-form">
        <input type="text" class="ins-search-input search-form-input" placeholder="" />
        <button type="submit" class="search-form-submit"></button>
    </form>
    <div class="ins-search">
    <div class="ins-search-mask"></div>
    <div class="ins-search-container">
        <div class="ins-input-wrapper">
            <input type="text" class="ins-search-input" placeholder="请输入关键词..." />
            <span class="ins-close ins-selectable"><i class="fa fa-times-circle"></i></span>
        </div>
        <div class="ins-section-wrapper">
            <div class="ins-section-container"></div>
        </div>
    </div>
</div>
<script>
(function (window) {
    var INSIGHT_CONFIG = {
        TRANSLATION: {
            POSTS: '文章',
            PAGES: '页面',
            CATEGORIES: '分类',
            TAGS: '标签',
            UNTITLED: '(无标题)',
        },
        ROOT_URL: '/',
        CONTENT_URL: '/content.json',
    };
    window.INSIGHT_CONFIG = INSIGHT_CONFIG;
})(window);
</script>
<script src="/js/insight.js"></script>

</div></li>
            </div>
          </div>
                
      </div>
    </div>

</header>



      
            
      <div id="content" class="outer">
        
          <section id="main" style="float:none;"><article id="post-Spark_DataFrame" style="width: 75%; float:left;" class="article article-type-post" itemscope itemprop="blogPost" >
  <div id="articleInner" class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 class="thumb" class="article-title" itemprop="name">
      【Spark】PySpark之DataFrame
    </h1>
  

      </header>
    
    <div class="article-meta">
      
	<a href="/2019/08/11/Spark_DataFrame/" class="article-date">
	  <time datetime="2019-08-11T10:05:58.673Z" itemprop="datePublished">2019-08-11</time>
	</a>

      
    <a class="article-category-link" href="/categories/Spark/">Spark</a>

      
	<a class="article-views">
	<span id="busuanzi_container_page_pv">
		阅读量<span id="busuanzi_value_page_pv"></span>
	</span>
	</a>

      

    </div>
    <div class="article-entry" itemprop="articleBody">
      
        <h2 id="1-思维导图"><a href="#1-思维导图" class="headerlink" title="1 思维导图"></a>1 思维导图</h2><p>首先先上一个整理的思维导图，这个与之前整理的RDD相类似，所以可视化的部分这里我就略去了。</p>
<p>DataFrame的API以及操作要比RDD复杂的多，可能功能更加强大吧，但是，很幸福的事情在于：</p>
<p>可以用SQL完成看起来超级复杂的操作，就问你幸不幸福，开不开心！！爽爆了……</p>
<p><img src="https://raw.githubusercontent.com/anxiang1836/FigureBed/master/img/20190821222604.png" alt></p>
<h2 id="2-数据的读入（比较RDD与DataFrame）"><a href="#2-数据的读入（比较RDD与DataFrame）" class="headerlink" title="2 数据的读入（比较RDD与DataFrame）"></a>2 数据的读入（比较RDD与DataFrame）</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> findspark</span><br><span class="line">findspark.init()</span><br></pre></td></tr></table></figure>
<h3 id="2-1-是使用RDD还是使用DataFrame？"><a href="#2-1-是使用RDD还是使用DataFrame？" class="headerlink" title="2.1.是使用RDD还是使用DataFrame？"></a>2.1.是使用RDD还是使用DataFrame？</h3><ul>
<li><p>RDD：</p>
<p>  RDD开始于SparkContext，如下：</p>
</li>
</ul>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">from</span> pyspark <span class="keyword">import</span> SparkContext</span><br><span class="line"><span class="keyword">from</span> pyspark <span class="keyword">import</span> SparkConf</span><br><span class="line">conf = SparkConf().setAppName(<span class="string">'MyProject_1'</span>)</span><br><span class="line">spark_rdd = SparkContext.getOrCreate(conf)</span><br></pre></td></tr></table></figure>
<ul>
<li>DataFrame:DataFrame开始与SparkSession，如下：</li>
</ul>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">from</span> pyspark.sql <span class="keyword">import</span> SparkSession</span><br><span class="line">spark_dataframe = SparkSession.builder.appName(<span class="string">"Python Spark Log Analysis"</span>).getOrCreate()</span><br></pre></td></tr></table></figure>
<h3 id="2-2-从外部文件导入？"><a href="#2-2-从外部文件导入？" class="headerlink" title="2.2 从外部文件导入？"></a>2.2 从外部文件导入？</h3><ul>
<li><p><strong>RDD：</strong></p>
<p>  用spark_rdd.textFile(logFile)</p>
</li>
<li><p><strong>DataFrame：</strong></p>
<p> 用spark_dataframe.read.text(logFile)</p>
<p> 或者借助pd，用spark_dataframe.createDataFrame(df)</p>
</li>
</ul>
<p>【补充】：Row的用法（这个是在RDD和DataFrame都通用的用法）</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">from</span> pyspark.sql <span class="keyword">import</span> Row</span><br><span class="line"></span><br><span class="line">data = (Row(</span><br><span class="line">        <span class="comment"># group的的计数是从1开始计数的</span></span><br><span class="line">        host          = match.group(<span class="number">1</span>),</span><br><span class="line">        client_identd = match.group(<span class="number">2</span>),</span><br><span class="line">        user_id       = match.group(<span class="number">3</span>),</span><br><span class="line">        date_time     = parse_apache_time(match.group(<span class="number">4</span>)),</span><br><span class="line">        method        = match.group(<span class="number">5</span>),</span><br><span class="line">        endpoint      = match.group(<span class="number">6</span>),</span><br><span class="line">        protocol      = match.group(<span class="number">7</span>),</span><br><span class="line">        response_code = int(match.group(<span class="number">8</span>)),</span><br><span class="line">        content_size  = size</span><br><span class="line">    ), <span class="number">1</span>)</span><br></pre></td></tr></table></figure>
<h2 id="3-数据操作（分析）"><a href="#3-数据操作（分析）" class="headerlink" title="3 数据操作（分析）"></a>3 数据操作（分析）</h2><p>这里面其实主要分成两种吧：</p>
<ul>
<li><p><strong>DataFrame的各种API：</strong></p>
<p>  用特别丰富的DataFrame的API去进行各种数据的操作；</p>
</li>
<li><p><strong>DataFrame支持的sql：</strong></p>
<p>  在我的心理，不用SQL处理的数据都不是个好数据，幸福点就在，可以再Spark里面写各种你想写的SQL，这就美滋滋了！</p>
</li>
</ul>
<h3 id="3-1-DataFrame的各种API"><a href="#3-1-DataFrame的各种API" class="headerlink" title="3.1 DataFrame的各种API"></a>3.1 DataFrame的各种API</h3><p>这里面，我还是想按照pandas的操作种类，给Spark进行大致分成3种操作吧：</p>
<p><strong>1.选择和筛选:</strong></p>
<p>   这个算是对于数据的最近本操作吧，对应于pandas中的.loc[]。</p>
<ul>
<li>df.select()</li>
<li>df.filter()</li>
</ul>
<p><strong>2.分组和聚合：</strong></p>
<ul>
<li><p>df.groupby(“某一列”).agg((“A列”,”count”),(“B列”，”sum”))</p>
<p>当然还有其他的聚合操作，可以直接上来对于某一列进行操作的，这里面，对于DataFrame的操作，都在pyspark.sql.functions中，具体就查看去吧，内容是在太丰富，感觉根本记不住！！尴尬……</p>
</li>
</ul>
<p><strong>3.对于列进行操作：</strong></p>
<p>   对于列进行操作这个就比较广义理解，可以是：</p>
<ul>
<li>新建一列；</li>
<li>给列改名;</li>
<li>修改列数据的数据类型格式；</li>
<li><p>……</p>
<p>用到的就是：</p>
</li>
<li><p>df.withColumn(参数1，参数2)</p>
<p>参数1：表示的是欲操作的列</p>
<p>参数2：表示的是欲操作的动作</p>
</li>
<li><p>df.withColumnRenamed(‘count’, ‘hostperday’)</p>
</li>
</ul>
<p><strong>4.表间操作：</strong></p>
<p>   表间操作其实主要还是表连接：</p>
<ul>
<li><p>df_1.join(df_2, ‘day’, ‘inner’)</p>
<p>参数1：表示欲连接的表</p>
<p>参数2：表示连接on的字段</p>
<p>参数3：连接的方式</p>
</li>
</ul>
<h3 id="3-2-DataFrame支持的sql"><a href="#3-2-DataFrame支持的sql" class="headerlink" title="3.2 DataFrame支持的sql"></a>3.2 DataFrame支持的sql</h3><p>【兴奋点来了】！！</p>
<p>想要在Spark中使用sql语句，步骤总共分为2步：</p>
<p><strong>1.为欲操作的表创建视图</strong></p>
<ul>
<li>df.createOrReplaceTempView(“TABLE”)</li>
</ul>
<p><strong>2.为所欲为的写SQL语句</strong></p>
<ul>
<li>spark.sql(“select * from DESCRIBE”).show()</li>
</ul>

      
    </div>
    <footer class="article-footer">
      
      
      
        
	<div id="comment">
		<!-- 来必力City版安装代码 -->
		<div id="lv-container" data-id="city" data-uid="MTAyMC80NTk2OS8yMjQ4MA==">
		<script type="text/javascript">
		   (function(d, s) {
		       var j, e = d.getElementsByTagName(s)[0];

		       if (typeof LivereTower === 'function') { return; }

		       j = d.createElement(s);
		       j.src = 'https://cdn-city.livere.com/js/embed.dist.js';
		       j.async = true;

		       e.parentNode.insertBefore(j, e);
		   })(document, 'script');
		</script>
		<noscript>为正常使用来必力评论功能请激活JavaScript</noscript>
		</div>
		<!-- City版安装代码已完成 -->
	</div>



      
      
        
  <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/DataFrame/">DataFrame</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/spark/">spark</a></li></ul>

      

    </footer>
  </div>
  
    
<nav id="article-nav">
  
    <a href="/2019/08/17/ML_Supervised_Learning/" id="article-nav-newer" class="article-nav-link-wrap">
      <strong class="article-nav-caption">上一篇</strong>
      <div class="article-nav-title">
        
          【机器学习】监督学习理论整理
        
      </div>
    </a>
  
  
    <a href="/2019/08/11/Spark_RDD/" id="article-nav-older" class="article-nav-link-wrap">
      <strong class="article-nav-caption">下一篇</strong>
      <div class="article-nav-title">【Spark】PySpark之RDD</div>
    </a>
  
</nav>

  
</article>

<!-- Table of Contents -->

  <aside id="toc-sidebar">
    <div id="toc" class="toc-article">
    <strong class="toc-title">文章目录</strong>
    
        <ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-思维导图"><span class="nav-number">1.</span> <span class="nav-text">1 思维导图</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-数据的读入（比较RDD与DataFrame）"><span class="nav-number">2.</span> <span class="nav-text">2 数据的读入（比较RDD与DataFrame）</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#2-1-是使用RDD还是使用DataFrame？"><span class="nav-number">2.1.</span> <span class="nav-text">2.1.是使用RDD还是使用DataFrame？</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-2-从外部文件导入？"><span class="nav-number">2.2.</span> <span class="nav-text">2.2 从外部文件导入？</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-数据操作（分析）"><span class="nav-number">3.</span> <span class="nav-text">3 数据操作（分析）</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#3-1-DataFrame的各种API"><span class="nav-number">3.1.</span> <span class="nav-text">3.1 DataFrame的各种API</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-2-DataFrame支持的sql"><span class="nav-number">3.2.</span> <span class="nav-text">3.2 DataFrame支持的sql</span></a></li></ol></li></ol>
    
    </div>
  </aside>

</section>
        
      </div>
      
      <footer id="footer">
  

  <div class="container">
      	<div class="row">
	      <p> Powered by <a href="http://hexo.io/" target="_blank">Hexo</a> and <a href="https://github.com/iTimeTraveler/hexo-theme-hiker" target="_blank">Hexo-theme-hiker</a> </p>
	      <p id="copyRightEn">Copyright &copy; 2013 - 2020 MaxMa All Rights Reserved.</p>
	      
	      
    		<p class="busuanzi_uv">
				访客数 : <span id="busuanzi_value_site_uv"></span> |  
				访问量 : <span id="busuanzi_value_site_pv"></span>
		    </p>
  		   
		</div>

		
  </div>
</footer>


<!-- min height -->

<script>
    var wrapdiv = document.getElementById("wrap");
    var contentdiv = document.getElementById("content");
    var allheader = document.getElementById("allheader");

    wrapdiv.style.minHeight = document.body.offsetHeight + "px";
    if (allheader != null) {
      contentdiv.style.minHeight = document.body.offsetHeight - allheader.offsetHeight - document.getElementById("footer").offsetHeight + "px";
    } else {
      contentdiv.style.minHeight = document.body.offsetHeight - document.getElementById("footer").offsetHeight + "px";
    }
</script>
    </div>
    <!-- <nav id="mobile-nav">
  
    <a href="/" class="mobile-nav-link">Home</a>
  
    <a href="/archives" class="mobile-nav-link">Archives</a>
  
    <a href="/categories" class="mobile-nav-link">Categories</a>
  
    <a href="/tags" class="mobile-nav-link">Tags</a>
  
    <a href="/about" class="mobile-nav-link">About</a>
  
</nav> -->
    

<!-- mathjax config similar to math.stackexchange -->

<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
    tex2jax: {
      inlineMath: [ ['$','$'], ["\\(","\\)"] ],
      processEscapes: true
    }
  });
</script>

<script type="text/x-mathjax-config">
    MathJax.Hub.Config({
      tex2jax: {
        skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
      }
    });
</script>

<script type="text/x-mathjax-config">
    MathJax.Hub.Queue(function() {
        var all = MathJax.Hub.getAllJax(), i;
        for(i=0; i < all.length; i += 1) {
            all[i].SourceElement().parentNode.className += ' has-jax';
        }
    });
</script>

<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>


  <link rel="stylesheet" href="/fancybox/jquery.fancybox.css">
  <script src="/fancybox/jquery.fancybox.pack.js"></script>


<script src="/js/scripts.js"></script>




  <script src="/js/dialog.js"></script>








	<div style="display: none;">
    <script src="https://s95.cnzz.com/z_stat.php?id=1260716016&web_id=1260716016" language="JavaScript"></script>
  </div>



	<script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js">
	</script>






  </div>

  <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="display: none;">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <h2 class="modal-title" id="myModalLabel">设置</h2>
      </div>
      <hr style="margin-top:0px; margin-bottom:0px; width:80%; border-top: 3px solid #000;">
      <hr style="margin-top:2px; margin-bottom:0px; width:80%; border-top: 1px solid #000;">


      <div class="modal-body">
          <div style="margin:6px;">
            <a data-toggle="collapse" data-parent="#accordion" href="#collapseOne" onclick="javascript:setFontSize();" aria-expanded="true" aria-controls="collapseOne">
              正文字号大小
            </a>
          </div>
          <div id="collapseOne" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingOne">
          <div class="panel-body">
            您已调整页面字体大小
          </div>
        </div>
      


          <div style="margin:6px;">
            <a data-toggle="collapse" data-parent="#accordion" href="#collapseTwo" onclick="javascript:setBackground();" aria-expanded="true" aria-controls="collapseTwo">
              夜间护眼模式
            </a>
        </div>
          <div id="collapseTwo" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingTwo">
          <div class="panel-body">
            夜间模式已经开启，再次单击按钮即可关闭 
          </div>
        </div>

        <div>
            <a data-toggle="collapse" data-parent="#accordion" href="#collapseThree" aria-expanded="true" aria-controls="collapseThree">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;关 于&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</a>
        </div>
         <div id="collapseThree" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingThree">
          <div class="panel-body">
            MaxMa
          </div>
          <div class="panel-body">
            Copyright © 2020 MaxMa All Rights Reserved.
          </div>
        </div>
      </div>


      <hr style="margin-top:0px; margin-bottom:0px; width:80%; border-top: 1px solid #000;">
      <hr style="margin-top:2px; margin-bottom:0px; width:80%; border-top: 3px solid #000;">
      <div class="modal-footer">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
      </div>
    </div>
  </div>
</div>
  
  <a id="rocket" href="#top" class=""></a>
  <script type="text/javascript" src="/js/totop.js?v=1.0.0" async=""></script>
  
    <a id="menu-switch"><i class="fa fa-bars fa-lg"></i></a>
  
<script type="text/x-mathjax-config">
    MathJax.Hub.Config({
        tex2jax: {
            inlineMath: [ ["$","$"], ["\\(","\\)"] ],
            skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code'],
            processEscapes: true
        }
    });
    MathJax.Hub.Queue(function() {
        var all = MathJax.Hub.getAllJax();
        for (var i = 0; i < all.length; ++i)
            all[i].SourceElement().parentNode.className += ' has-jax';
    });
</script>
<script src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
</body>
</html>